# sqlalchemy
from sqlalchemy import create_engine, ForeignKey, Column, Integer, String, \
					Text, DateTime, and_, or_, SmallInteger, Float, DECIMAL, \
					desc, asc, Table, join, event

from sqlalchemy.orm import relationship, backref, sessionmaker, scoped_session, aliased, mapper

from sqlalchemy.ext.declarative import declarative_base

from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method

from sqlalchemy.orm.collections import attribute_mapped_collection

# sys
import datetime

URI = r'sqlite:///datebase/JT808Api_1_0.db'
engine = create_engine(URI, pool_recycle=7200)

Base = declarative_base()
db_session = scoped_session(sessionmaker(autocommit=False,autoflush=False,bind=engine))
Base.query = db_session.query_property()



#
class User(Base):
	"""docstring for User"""
	__tablename__ = 'user'

	id = Column('id', Integer, primary_key=True)
	phone_number = Column('phone_number', String(12), index=True)
	password = Column('password', String(30))
	nickname = Column('nickname', String(30), index=True, nullable=True,default='guest')
	registe_time = Column('registe_time', DateTime, index=True, default=datetime.datetime.now)



#
if __name__ == '__main__':
	#初始化数据库表结构（需提前建好数据库）
	Base.metadata.create_all(engine)

